import { request } from "@umijs/max";;
import { UMS_REQUEST_PREFIX } from "@/utils/config";
import { dictTypeTypes, dictValueTypes, destinaionTypes, serviceTypes, warehouseTypes, pager, weightRatioTypes } from '@/constants/types';

// 公共部分
/**
 * 国内地址下拉列表
 * @returns 
 */
export async function fetchaddressOptions() {
  return request(`${UMS_REQUEST_PREFIX}/base/domesticAddress/addressOptions`, {
    method: 'POST',
    dataField: 'data'
  });
}
// 字典
/**
 * 获取字典项列表
 * @returns 
 */
export async function fetchListDictType() {
  return request(`${UMS_REQUEST_PREFIX}/base/dict/listDictType`, {
    method: 'POST',
    dataField: 'data'
  });
}
/**
 * 
 * @returns 获取字典项下拉
 */
export async function fetchListDictTypeOptions(params: {dictType: string}) {
  return request(`${UMS_REQUEST_PREFIX}/base/dict/options`, {
    method: 'POST',
    data: params,
    dataField: 'data',
  });
}
/**
 * 
 * @returns 获取所有字典下拉
 */
export async function fetchAllDictOptions() {
  return request(`${UMS_REQUEST_PREFIX}/base/dict/allOptions`, {
    method: 'POST',
    dataField: 'data',
  });
}
/**
 * 获取字典值列表
 * @returns 
 */
export async function fetchListDictTypeValue(params: { dictType: string | undefined; }) {
  return request(`${UMS_REQUEST_PREFIX}/base/dict/listDictValue`, {
    method: 'POST',
    data: params,
    dataField: 'data'
  });
}
/**
 * 添加字典项
 * @param params 
 * @returns 
 */
export async function addDictType(params: dictTypeTypes) {
  return request(`${UMS_REQUEST_PREFIX}/base/dict/addDictType`, {
    method: 'POST',
    data: params
  });
}
/**
 * 
 * @param params 添加字典值
 * @returns 
 */
export async function addDictValue(params: dictValueTypes) {
  return request(`${UMS_REQUEST_PREFIX}/base/dict/addDictValue`, {
    method: 'POST',
    data: params
  });
}
/**
 * 
 * @param params 更新字典值
 * @returns 
 */
export async function updateDictValue(params: dictValueTypes) {
  return request(`${UMS_REQUEST_PREFIX}/base/dict/updateDictValue`, {
    method: 'POST',
    data: params
  });
}
/**
 * 
 * @param params 删除字典值
 * @returns 
 */
export async function deleteDictValue(params: any) {
  return request(`${UMS_REQUEST_PREFIX}/base/dict/deleteDictValue`, {
    method: 'POST',
    data: params
  });
}

// 服务商
/**
 * 
 * @param params 获取服务商列表
 * @returns 
 */
export async function fetchServiceProviderList(params: {
  pageNum: number | undefined;
  pageSize: number | undefined;
  name?: string;
  type?: string;
}) {
  return request(`${UMS_REQUEST_PREFIX}/base/serviceProvider/list`, {
    method: 'POST',
    data: params,
    dataField: 'data'
  });
}
/**
 * 获取服务商下拉列表
 * @param params type: 类型
 * @returns 
 */
export async function fetchServiceProviderOptions(params: {
  type?: string;
}) {
  return request(`${UMS_REQUEST_PREFIX}/base/serviceProvider/options`, {
    method: 'POST',
    data: params,
    dataField: 'data'
  });
}
/**
 * 服务商详情
 * @param params 
 * @returns 
 */
export async function fetchServiceProviderDetail(params: {
  id: string;
}) {
  return request(`${UMS_REQUEST_PREFIX}/base/serviceProvider/detail`, {
    method: 'POST',
    data: params,
    dataField: 'data'
  });
}
/**
 * 新建服务商
 * @param params 
 * @returns 
 */
export async function addServiceProvider(params: serviceTypes) {
  return request(`${UMS_REQUEST_PREFIX}/base/serviceProvider/add`, {
    method: 'POST',
    data: params,
  });
}
/**
 * 修改服务商
 * @param params 
 * @returns 
 */
export async function updateServiceProvider(params: serviceTypes) {
  return request(`${UMS_REQUEST_PREFIX}/base/serviceProvider/update`, {
    method: 'POST',
    data: params
  });
}
/**
 * 删除服务商
 * @param params 
 * @returns 
 */
export async function delServiceProvider(params: {id: string}) {
  return request(`${UMS_REQUEST_PREFIX}/base/serviceProvider/delete`, {
    method: 'POST',
    data: params
  });
}

// 目的地
/**
 * 获取目的地列表
 * @param params 
 * @returns 
 */
export async function fetchDestinationList(params: {
  pageNum: number,
  pageSize: number,
  country?: string,
  destType?: string,
  destCode?: string
}) {
  return request(`${UMS_REQUEST_PREFIX}/base/destination/list`, {
    method: 'POST',
    data: params,
    dataField: 'data'
  });
}
/**
 * 获取目的地下拉列表
 * @param params 
 * @returns 
 */
export async function fetchDestinationOptions(params: { 
  country?: string,
  destType?: string,}) {
  return request(`${UMS_REQUEST_PREFIX}/base/destination/options`, {
    method: 'POST',
    data: params,
    dataField: 'data'
  });
}
/**
 * 获取目的地详情
 * @param params 
 * @returns 
 */
export async function fetchDestinationDetail(params: {id: string}) {
  return request(`${UMS_REQUEST_PREFIX}/base/destination/detail`, {
    method: 'POST',
    data: params
  });
}
/**
 * 新建目的地
 * @param params 
 * @returns 
 */
export async function addDestination(params: destinaionTypes) {
  return request(`${UMS_REQUEST_PREFIX}/base/destination/add`, {
    method: 'POST',
    data: params
  });
}
/**
 * 编辑目的地
 * @param params 
 * @returns 
 */
export async function updateDestination(params: destinaionTypes) {
  return request(`${UMS_REQUEST_PREFIX}/base/destination/update`, {
    method: 'POST',
    data: params
  });
}
/**
 * 删除目的地
 * @param params 
 * @returns 
 */
export async function delDestination(params: {id: string}) {
  return request(`${UMS_REQUEST_PREFIX}/base/destination/delete`, {
    method: 'POST',
    data: params
  });
}

// 国内仓库
/**
 * 获取国内仓库
 * @param params 
 * @returns 
 */
export async function fetchDomesticWhList(params: {
  pageNum: number,
  pageSize: number,
}) {
  return request(`${UMS_REQUEST_PREFIX}/base/domesticWh/list`, {
    method: 'POST',
    data: params,
    dataField: 'data'
  });
}
/**
 * 获取国内仓库下拉
 * @param params 
 * @returns 
 */
export async function fetchDomesticWhOptions(params: {id?: string}) {
  return request(`${UMS_REQUEST_PREFIX}/base/domesticWh/options`, {
    method: 'POST',
    data: params,
    dataField: 'data'
  });
}
/**
 * 
 * @param params 获取国内仓库详情
 * @returns 
 */
export async function fetchDomesticWhDetail(params: {id: string}) {
  return request(`${UMS_REQUEST_PREFIX}/base/domesticWh/detail`, {
    method: 'POST',
    data: params
  });
}
/**
 * 新增国内仓库
 * @param params 
 * @returns 
 */
export async function addDomesticWh(params: warehouseTypes) {
  return request(`${UMS_REQUEST_PREFIX}/base/domesticWh/add`, {
    method: 'POST',
    data: params
  });
}
/**
 * 编辑国内仓库
 * @param params 
 * @returns 
 */
export async function updateDomesticWh(params: warehouseTypes) {
  return request(`${UMS_REQUEST_PREFIX}/base/domesticWh/update`, {
    method: 'POST',
    data: params
  });
}
/**
 * 删除国内仓库
 * @param params 
 * @returns 
 */
export async function delDomesticWh(params: {id: string | undefined}) {
  return request(`${UMS_REQUEST_PREFIX}/base/domesticWh/delete`, {
    method: 'POST',
    data: params
  });
}
/**
 * 启用国内仓
 * @param params 
 * @returns 
 */
export async function enableDomesticWh(params: {id: string | undefined}) {
  return request(`${UMS_REQUEST_PREFIX}/base/domesticWh/enable`, {
    method: 'POST',
    data: params
  });
}
/**
 * 禁用国内仓
 * @param params 
 * @returns 
 */
export async function disableDomesticWh(params: {id: string | undefined}) {
  return request(`${UMS_REQUEST_PREFIX}/base/domesticWh/disable`, {
    method: 'POST',
    data: params
  });
}
/**
 * 根据编码查询国内仓详情
 * @param params 
 * @returns 
 */
export async function baseDomesticWhQueryByCode(params: {code: string}) {
  return request(`${UMS_REQUEST_PREFIX}/base/domesticWh/queryByCode`, {
    method: 'POST',
    data: params,
    dataField: 'data'
  });
}
// 结算年周
/**
 * 根据年份获取周次
 * @param params 
 * @returns 
 */
export async function fetchSettlementWeeksByYear(params: {year: string}) {
  return request(`${UMS_REQUEST_PREFIX}/base/settlementDate/weeksByYear`, {
    method: 'POST',
    data: params,
    dataField: 'data'
  });
}
/**
 * 获取最近周次信息
 * @param params 
 * @returns 
 */
export async function fetchSettlementDateLatestWeek() {
  return request(`${UMS_REQUEST_PREFIX}/base/settlementDate/latestWeek`, {
    method: 'POST',
    dataField: 'data'
  });
}
/**
 * 获取所有周次信息
 * @param params 
 * @returns 
 */
export async function fetchSettlementDateWholeDates() {
  return request(`${UMS_REQUEST_PREFIX}/base/settlementDate/wholeDates`, {
    method: 'POST',
    dataField: 'data'
  });
}

// 货重比
/**
 * 货重比列表
 * @param params 
 * @returns 
 */
export async function fetchBaseWeightRatioList(params: pager) {
  return request(`${UMS_REQUEST_PREFIX}/base/weightRatio/list`, {
    method: 'POST',
    data: params,
    dataField: 'data',
  });
}
/**
 * 货重比详情
 * @param params 
 * @returns 
 */
export async function fetchBaseWeightRatioDetail(params: {id: string}) {
  return request(`${UMS_REQUEST_PREFIX}/base/weightRatio/detail`, {
    method: 'POST',
    data: params,
    dataField: 'data',
  });
}
/**
 * 新增货重比
 * @param params 
 * @returns 
 */
export async function baseWeightRatioAdd(params: weightRatioTypes) {
  return request(`${UMS_REQUEST_PREFIX}/base/weightRatio/add`, {
    method: 'POST',
    data: params,
  });
}
/**
 * 编辑货重比
 * @param params 
 * @returns 
 */
export async function baseWeightRatioUpdate(params: weightRatioTypes) {
  return request(`${UMS_REQUEST_PREFIX}/base/weightRatio/update`, {
    method: 'POST',
    data: params,
  });
}
/**
 * 删除货重比
 * @param params 
 * @returns 
 */
export async function baseWeightRatioDelete(params: {id: string}) {
  return request(`${UMS_REQUEST_PREFIX}/base/weightRatio/delete`, {
    method: 'POST',
    data: params,
  });
}
/**
 * 文件模块路径
 * @returns 
 */
export async function fetchDictTemplatePath(params: {templateKey: string}) {
  return request(`${UMS_REQUEST_PREFIX}/base/dict/template`, {
    method: 'POST',
    data: params,
    dataField: 'data'
  });
}